<?php

/**
 * Description of Repository
 *
 * Copyright (c) 2011 Tomáš Holub (tomas.holub@webadvice.cz)
 * 
 * @author Tomáš Holub (tomas.holub@webadvice.cz)
 * @package OverFishCMS
 */

namespace OverFish\Model;

use Nette;

class Repository extends Nette\Object {

    protected $mapper;
    /** @var \Nette\DI\Container */
    private $context;

    public function __construct(\Nette\DI\Container $container, IMapper $mapper) {
        $this->mapper = $mapper;
        $this->context = $container;
    }

    public function getDataSource() {
        return new LazyCollection($this->mapper, $this->mapper->getAllDataSource());
    }

    public function save($item) {

        $this->mapper->save($item);

        return $item;
    }
    
    public function delete($item) {

        $this->mapper->delete($item);

    }
    
    public function find($id) {
        return $this->mapper->find($id);
    }
    
    public function findAll() {
        return $this->mapper->findAll();
    }
    
    /**
     * @return \Nette\DI\Container
     */
    final public function getContext()
    {
        return $this->context;
    }

    /**
     * @return \DibiConnection
     */
    final public function getDatabase()
    {
        return $this->context->database;
    }
}

